if(!Pb) var Pb={};
Pb.ShineSky=(function () {
        //宇宙特效
        "use strict";
		var canvas,ctx,w,h;
        var stars = [],
            count = 0,
			requestFrame = window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.oRequestAnimationFrame ||
            window.msRequestAnimationFrame ||
            function (callback) {
                window.setTimeout(callback, 1000 / 60);
            };

        var canvas2 = document.createElement('canvas'),
            ctx2 = canvas2.getContext('2d');
        canvas2.width = 100;
        canvas2.height = 100;
        var half = canvas2.width / 2,
            gradient2 = ctx2.createRadialGradient(half, half, 0, half, half, half);
        gradient2.addColorStop(0.025, '#ffffff');
        gradient2.addColorStop(1, 'transparent');

        ctx2.fillStyle = gradient2;
        ctx2.beginPath();
        ctx2.arc(half, half, half, 0, Math.PI * 2);
        ctx2.fill();
        // End cache
        function random(min, max) {
            if (arguments.length < 2) {
                max = min;
                min = 0;
            }

            if (min > max) {
                var hold = max;
                max = min;
                min = hold;
            }

            return Math.floor(Math.random() * (max - min + 1)) + min;
        }

        function maxOrbit(x, y) {
            var max = Math.max(x, y),
                diameter = Math.round(Math.sqrt(max * max + max * max));
            return diameter / 2;
            //星星移动范围，值越大范围越小，
        }

        var Star = function () {
            //星星半径
            this.radius = random(1, 10);
            //星星初始坐标
            this.orbitX = random(w);
            this.orbitY = random(h);
            //运行时间
            this.timePassed = random(1000);
            //变化速度
            this.speed = random(0.5);
            //透明度
            this.alpha = random(1);
			this.alphadir = 1;
            count++;
            stars[count] = this;
        }

        Star.prototype.draw = function () {
            var twinkle = random(10);
			if(this.alpha>0.95&&this.alphadir==1)
				this.alphadir=-1;
			else if(this.alpha<0.05&&this.alphadir==-1)
				this.alphadir=1;
			if(twinkle<5)
				this.alpha += 0.05*this.alphadir*this.speed;

            ctx.globalAlpha = this.alpha;
            ctx.drawImage(canvas2, this.orbitX - (this.radius/2), this.orbitY - (this.radius/2), this.radius, this.radius);
            this.timePassed += this.speed;
        }

        function animation() {
            ctx.globalCompositeOperation = 'source-over';
            ctx.globalAlpha = 0.5;
            //星星颜色
            ctx.fillStyle = '#000';
            ctx.fillRect(0, 0, w, h)

            ctx.globalCompositeOperation = 'lighter';
            for (var i = 1, l = stars.length; i < l; i++) {
                stars[i].draw();
            };

            requestFrame(animation);
        }
		return{
			init:function(canvasid,starcount){
				canvas = document.getElementById(canvasid),
				ctx = canvas.getContext('2d'),
				w = canvas.width = window.innerWidth,
				h = canvas.height = window.innerHeight
				for (var i = 0; i < starcount; i++) {
					new Star();
				}
				animation();
			}
		}
})();